home *** CD-ROM | disk | FTP | other *** search
- /*
- * DSPLDRV.C -- Display drivers
- *
- * Copyright (C) 1990,1991 by Alef Null. All rights reserved.
- * Author(s): Jarkko Vuori, OH2LNS
- * Modification(s):
- */
-
- #include <graph.h>
- #include <stdio.h>
- #include <string.h>
- #include <malloc.h>
- #include <math.h>
- #include "dspldrv.h"
-
-
- struct {
- struct xycoord lowerleft,
- highright;
- int pixperchrx,
- pixperchry;
- int dx, // number of pixels in x direction
- dy; // number of pixels in y direction
- int colors;
- } dimensions;
- static int *prev;
-
-
- /*
- * Initializes display
- */
- int InitDspl(int dx, int dy) {
- struct videoconfig config;
- int x, y;
- char buf[80];
-
- if (!(prev = calloc(dx, sizeof(int))) ||
- _setvideomode(_VRES16COLOR) ||
- _setvideomode(_HERCMONO)) {
- _getvideoconfig(&config);
-
- dimensions.dx = dx;
- dimensions.dy = dy;
-
- dimensions.colors = config.numcolors;
-
- /* calculate screen dimensions */
- dimensions.lowerleft.xcoord = (config.numxpixels-dx)/2;
- dimensions.lowerleft.ycoord = (config.numypixels-dy)/2;
-
- dimensions.highright.xcoord = dimensions.lowerleft.xcoord+dx;
- dimensions.highright.ycoord = dimensions.lowerleft.ycoord+dy;
-
- dimensions.pixperchrx = config.numxpixels/config.numtextcols;
- dimensions.pixperchry = config.numypixels/config.numtextrows;
-
- /* plot surrounding rectangle */
- _setbkcolor(_BLUE); _setcolor(7); _settextcolor(7);
- _rectangle(_GBORDER, dimensions.lowerleft.xcoord-1,
- dimensions.lowerleft.ycoord,
- dimensions.highright.xcoord,
- dimensions.highright.ycoord+1);
- /* plot horizontal ticks */
- for (x = dimensions.lowerleft.xcoord; x <= dimensions.highright.xcoord; x += dx/8) {
- _moveto(x, dimensions.highright.ycoord+1);
- _lineto(x, dimensions.highright.ycoord+1+dimensions.pixperchry/2);
- }
- /* plot vertical ticks */
- for (y = dimensions.highright.ycoord; y >= dimensions.lowerleft.ycoord; y -= dy/8) {
- _moveto(dimensions.highright.xcoord+1, y);
- _lineto(dimensions.highright.xcoord+1+dimensions.pixperchrx, y);
- }
-
- /* draw axis marks */
- _settextposition(config.numtextrows/2, 80-4);
- _outtext("[dB]");
- _settextposition(config.numtextrows, 40-2);
- _outtext("[Hz]");
-
- /* and finally static text fields */
- sprintf(buf, "DSP CARD 3 FFT Spectrum Analyzer (%s)", __DATE__);
- _settextposition(1, 1+(80-strlen(buf))/2);
- _outtext(buf);
-
- _settextposition(10,1);
- _outtext("Marker:");
- _settextposition(6,1);
- _outtext("N:");
-
- return(0);
- } else
- return (-1);
- }
-
-
- /*
- * Plot one data value
- */
- void PlotPoint(int x, int y) {
- static int last_y, prev_last_y;
-
- if (x) {
- /* first erase */
- _setcolor(0);
- _moveto(dimensions.lowerleft.xcoord+x-1, dimensions.highright.ycoord-prev_last_y);
- _lineto(dimensions.lowerleft.xcoord+x, dimensions.highright.ycoord-prev[x]);
-
- /* then draw */
- _setcolor((dimensions.colors > 2) ? 3 : 7);
- _moveto(dimensions.lowerleft.xcoord+x-1, dimensions.highright.ycoord-last_y);
- _lineto(dimensions.lowerleft.xcoord+x, dimensions.highright.ycoord-y);
- }
-
- prev_last_y = prev[x];
- last_y = y;
- prev[x] = y;
- }
-
-
- /* plot marker symbol */
- static void DrawMarkerSymbol(int type, int x, int y, int color) {
- const int dim = 3;
-
- _setcolor(color);
- if (type)
- _rectangle(_GBORDER, dimensions.lowerleft.xcoord+x-dim, dimensions.highright.ycoord-(y-dim),
- dimensions.lowerleft.xcoord+x+dim, dimensions.highright.ycoord-(y+dim));
- else
- _ellipse(_GBORDER, dimensions.lowerleft.xcoord+x-dim, dimensions.highright.ycoord-(y-dim),
- dimensions.lowerleft.xcoord+x+dim, dimensions.highright.ycoord-(y+dim));
- }
-
-
- /* plot one marker */
- static void DrawMarker(int type, int line, int prev_x, int prev_y, int x, int y, double freq, double amplitude) {
- char buf[80];
-
- _settextwindow(line, 1,
- line+1,10);
-
- /* then erase previous marker */
- if (prev_x) {
- _clearscreen(_GWINDOW);
- DrawMarkerSymbol(type, prev_x, prev_y, 0);
- }
-
- /* and finally draw a new one */
- if (x) {
- DrawMarkerSymbol(type, x, y, (dimensions.colors > 2) ? 3 : 7);
- sprintf(buf, "%5.0lf Hz\n %2.1lf dB", freq, amplitude);
- _outtext(buf);
- }
- }
-
-
- /*
- * Plot card status
- */
- void PlotStatus(long N, long samplef) {
- static long prev_samplef;
- int x;
- char buf[80];
-
- /* update N display */
- _settextwindow(7, 1,
- 7, 10);
- sprintf(buf, "%5ld", N);
- _clearscreen(_GWINDOW);
- _outtext(buf);
-
- /* update frequency scale if needed */
- if (samplef != prev_samplef) {
- _settextwindow(1, 1,
- 30, 80);
- for (x = dimensions.lowerleft.xcoord; x <= dimensions.highright.xcoord; x += dimensions.dx/8) {
- sprintf(buf, "%5d", (int)(samplef*(x-dimensions.lowerleft.xcoord)/1024));
- _settextposition(dimensions.highright.ycoord/dimensions.pixperchry+2, x/dimensions.pixperchrx-3);
- _outtext(buf);
- }
-
- prev_samplef = samplef;
- }
- }
-
-
- /*
- * Plot marker
- */
- void PlotMarker(int x1, int y1, double freq1, double amplitude1,
- int x2, int y2, double freq2, double amplitude2) {
- static int prev_x1, prev_y1,prev_x2, prev_y2;
- char buf[80];
-
- if (prev_x1 != x1 || prev_y1 != y1) {
- DrawMarker(1, 11, prev_x1, prev_y1, x1, y1, freq1, amplitude1);
- prev_x1 = x1; prev_y1 = y1;
- }
-
- if (prev_x2 != x2 || prev_y2 != y2) {
- DrawMarker(0, 13, prev_x2, prev_y2, x2, y2, freq2, amplitude2);
- prev_x2 = x2; prev_y2 = y2;
- }
-
- _settextwindow(16, 1,
- 16, 10);
- _clearscreen(_GWINDOW);
- sprintf(buf, "%+2.1lf dB", amplitude1-amplitude2);
- _outtext(buf);
- }
-
-
- /*
- * releases display
- */
- void ReleaseDspl() {
- _setvideomode(_DEFAULTMODE);
- free(prev);
- }
-